<%@ page contentType="text/html;charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<title>查看系统用户列表</title>
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/systemUserMgrAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/jquery-latest.pack.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/noConflictOfJquery.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/forCSS.js'></script>
		<script type="text/javascript">
	 var g_systemusergroupinfo = ""; //这个g_systemusergroupinfo是全局变量 
	  var totalcount = -1; //查询到的总行数
      var page;   //dwr分页的page对象，注意在页面中是一个Json对象
      var sysuserCache ={};
      var systemusergroupid;

	//主要是给页面的系统用户组select框赋值
	function setSystemusergroupList() {
		systemUserMgrAction.getSystemUserGroupInfo(mycallback);
	}
	var mycallback = function setList(systemusergroupValue)//回调函数
	{
		g_systemusergroupinfo = systemusergroupValue;
		var s = $("systemusergroup");
		DWRUtil.removeAllOptions(s);
		s.options[0] = new Option("请选择用户组", '0');
		for ( var i = 1; i < systemusergroupValue.length + 1; i++) {
			var opt = new Option(
					systemusergroupValue[i - 1].systemusergroupname,
					systemusergroupValue[i - 1].systemusergroupid);
			s.options[i] = opt;
		}
		
		//给编辑系统用户框赋值
		var sf = $("systemusergroupid");
		DWRUtil.removeAllOptions(sf);
		for ( var i = 0; i < systemusergroupValue.length ; i++) {
			var optf = new Option(
					systemusergroupValue[i].systemusergroupname,
					systemusergroupValue[i].systemusergroupid);
			sf.options[i] = optf;
		}
		
		
	}
	function selectChange(){
		systemusergroupid = $("systemusergroup").options[$("systemusergroup").selectedIndex].value; //给systemusergroupid赋值
	}

	//查询总行数
	function searchTotalCount(){
		if(systemusergroupid==""){
			alert("请选择用户组！");
		}
		systemUserMgrAction.getAGroupIDSysUserTotalRows(systemusergroupid,tcbck); //查询系统用户
	}
	
	var tcbck = function tc_bck(bckcount){
	totalcount = bckcount; // 给总行数赋值
	systemUserMgrAction.listSystemUserPerPageByGroupID(1,totalcount,systemusergroupid,rendersucallback);
	}
	
	//根据id返回系统用户列表
	var rendersucallback  = function rendersucb(sulst){
		if(sulst==null){
			if($('pageTable').style.visibility == 'visible'){
			$('pageTable').style.visibility = 'hidden';
		    }
			if($('MyTable').style.visibility == 'visible'){
				$('MyTable').style.visibility = 'hidden';
			}
			alert("查询该组的用户为空！");
			return ;
		}

		if($('sysuserdiv').style.visibility == 'visible'){
			$('sysuserdiv').style.visibility = 'hidden';
		}
		
		if($('pageTable').style.visibility == 'hidden'){
		$('pageTable').style.visibility = 'visible';
	    }
		if($('MyTable').style.visibility == 'hidden'){
			$('MyTable').style.visibility = 'visible';
		}		
		DWRUtil.removeAllRows('ttb', { filter:function(tr) {
		      return (tr.id != "pattern");
			    }});
		var su,id;
		 for (var i =0; i < sulst.length ; i++) {
			 su = sulst[i];
			  id = su.systemuserid;
			  //alert(id);
			  dwr.util.cloneNode("pattern", { idSuffix:id });
		      dwr.util.setValue("tableid"+id, su.systemuserid);//隐藏项
		      dwr.util.setValue("tablegrpid"+id, su.systemusergroupid);//隐藏项
		      dwr.util.setValue("tablename"+id, su.systemusername);
		      dwr.util.setValue("tablenickname"+id,su.systemusernickname);
		      if(su.systemusersex=="1"){
		       dwr.util.setValue("tablesex"+id,"男");
		      }else{
		       dwr.util.setValue("tablesex"+id,"女");
		      }
		      dwr.util.setValue("tablepwd"+id,su.systemuserpassword);//隐藏项
		      dwr.util.setValue("tableidcardno"+id,su.systemuseridentitycardno);
		      dwr.util.setValue("tabletelephone"+id,su.systemusertelephone); 
		      dwr.util.setValue("tableemail"+id,su.systemuseremail);//隐藏项
		      dwr.util.setValue("tableaddress"+id,su.systemuseraddress); 
		      dwr.util.setValue("tablesysuserind"+id,su.systemuserind);//隐藏项
		      dwr.util.setValue("tablebirthday"+id,su.systemuserbirthday); //隐藏项
		      dwr.util.setValue("tablebirthplace"+id,su.systemuserbirthplace); //隐藏项
		      dwr.util.setValue("cbx" + id, su.systemuserid);
		 	  $("pattern" + id).style.display= "";
		 	  sysuserCache[id] = su;
		   }
		   
		    var Ptr= document.getElementById('MyTable').getElementsByTagName('tr'); 
		   	for (i=1;i<Ptr.length+1;i++) {
			Ptr[i-1].className = (i%2>0)?"row_odd":"row_even";
			} 
		   
		   	setPageInfo();
		    tbCSS();
			}
			
			
	function setPageInfo(){
        $('pageTd').innerHTML = '';
        systemUserMgrAction.getPage({     
            callback:function(data){
                page = data;
                if(page.totalPage != 0){
                    var pageSpan = document.createElement('span');
                    pageSpan.innerHTML = '共 '+totalcount+' 条 '+'   第 '+page.currentPage+' 页    共'+page.totalPage+' 页 ';
                    $('pageTd').appendChild(pageSpan);
                    var aFirst = document.createElement('a');
                    aFirst.setAttribute('href','javascript:getFirstData()');
                    aFirst.innerHTML = '首页';
                    $('pageTd').appendChild(aFirst);
                    var aPrevious = document.createElement('a');
                    aPrevious.setAttribute('href','javascript:getPreviousData()');
                    aPrevious.innerHTML = '上一页 ';
                    $('pageTd').appendChild(aPrevious);
                    var aNext = document.createElement('a');
                    aNext.setAttribute('href','javascript:getNextData()');
                    aNext.innerHTML = '下一页 ';
                    $('pageTd').appendChild(aNext);
                    var aLast = document.createElement('a');
                    aLast.setAttribute('href','javascript:getLastData()');
                    aLast.innerHTML = '尾页';
                    $('pageTd').appendChild(aLast);    
                }               
            }
        });
        $('loading').style.display = 'none';
    	}
			function getFirstData(){
				page.currentPage = 1;
				getDataPerPage();
			}
			
		   function getPreviousData(){
		        if(page.currentPage>1){
		            page.currentPage--;
		        }
		        getDataPerPage();
		    }
		    
		    function getNextData(){
		        if(page.currentPage<page.totalPage){
		            page.currentPage++;
		        }
		        getDataPerPage();
		    }

			
			function getLastData(){
				page.currentPage = page.totalPage;
				getDataPerPage();
			}
			
			function getDataPerPage(){
				$('loading').style.display = 'block';
				systemUserMgrAction.listSystemUserPerPageByGroupID(page.currentPage,totalcount,systemusergroupid,rendersucallback);
			}	

			function editClicked(eleid) {
				  if($('sysuserdiv').style.visibility == 'hidden'){
						$('sysuserdiv').style.visibility = 'visible';
					}
				  var suser = sysuserCache[eleid.substring(4)]; 
				   dwr.util.setValues(suser);   
					
			}
			
			//删除
			function delClicked(eleid){
			//得到的eleid为"mydelete{id}"
			var systemuserid = eleid.substring(8);
			systemUserMgrAction.delelteSystemUserByID(systemuserid,delcb)
			}
			var delcb = function del_cb(stas){
				alert(stas);
				searchTotalCount();
			}
			
			//更新系统用户
			function writeSystemUser(){
			var sysuser = { systemuserid:null, systemuserind:null, systemuserpassword:null,systemuseremail:null,systemuserbirthday:null,systemuserbirthplace:null,systemuseridentitycardno:null,systemuseraddress:null,systemusername:null,systemusernickname:null,systemusersex:null,systemusertelephone:null,systemusergroupid:null };
			dwr.util.getValues(sysuser);
			var ay = new Array(sysuser.systemuserid, sysuser.systemuserind, sysuser.systemuserpassword,sysuser.systemuseremail,sysuser.systemuserbirthday,sysuser.systemuserbirthplace,sysuser.systemuseridentitycardno,sysuser.systemuseraddress,sysuser.systemusername,sysuser.systemusernickname,sysuser.systemusersex,sysuser.systemusertelephone,sysuser.systemusergroupid);
			if(sysuser.systemusername==""){
				alert("请填写系统用户名！");
				return;
			  }
		   if(sysuser.systemusersex==""){
				alert("请填写系统用户性别！");
				return;
			  }
		   if(sysuser.systemusergroupid==""){
				alert("请填写系统用户组！");
				return;
			  }
			systemUserMgrAction.updateSystemUser(ay+"",writecallback)
			}
			var writecallback = function wcallback(status){
				 alert(status);
				searchTotalCount();
			 }
			
			//输入框清空
			function clearSystemUser(){
			dwr.util.setValues({systemusername:null,systemusernickname:null,systemusertelephone:null });
			}
		
</script>
	</head>
	<body onload="javascript:setSystemusergroupList()">
		<div id="page_container">
			<%@include file="userbanner.jsp"%>
			<div id="outlier">
				<div align="center">
					系统用户组:
					<select class="common_select" name="systemusergroup"
						id="systemusergroup" style="width: 120"
						onchange="javascript:selectChange();">
					</select>
					<input class="common_button" type="submit" name="button"
						id="button" value="查询" onclick="javascript:searchTotalCount();" />
				</div>
				<h2>
					系统用户列表
				</h2>
				<table id="MyTable" class="table_common table_list_style" style="visibility: hidden;">
					<tr>
						<th width="14%">
							<div align="center">
								用户姓名
							</div>
						</th>
						<th width="8%">
							<div align="center">
								显示名
							</div>
						</th>
						<th width="10%">
							<div align="center">
								性别
							</div>
						</th>
						<th width="14%">
							<div align="center">
								电话
							</div>
						</th>
						<th width="11%">
							<div align="center">
								编辑
							</div>
						</th>
						<th width="11%">
							<div align="center">
								删除
							</div>
						</th>
					</tr>
					<tbody id="ttb">
						<tr id="pattern" style="display: none;">
							<!-- 隐藏的项目 -->
							<div id="tableid" style="display: none" />
								<div id="tablegrpid" style="display: none" />
									<div id="tablepwd" style="display: none" />
										<div id="tableemail" style="display: none" />
											<div id="tablesysuserind" style="display: none" />
												<div id="tablebirthday" style="display: none" />
													<div id="tablebirthplace" style="display: none" />
														<!-- 隐藏的项目 -->
							<td height="18">
								<div id="tablename">
								</div>
							</td>
							<td height="18">
								<div id="tablenickname">
								</div>
							</td>
							<td height="18">
								<div id="tablesex">
								</div>
							</td>
							<td height="18">
								<div id="tabletelephone">
								</div>
							</td>
							<td height="18">
								<div>
									<a href="#" id="edit" onclick="javascript:editClicked(this.id)"><img
											src="../images/037.gif" width="9" height="9" /> </a>
								</div>
							</td>
							<td height="18">
								<div>
									<a href="#" id="mydelelt"
										onclick="javascript:if(confirm('确认删除！')) delClicked(this.id)">
										<img src="../images/010.gif" width="9" height="9" /> </a>
								</div>
							</td>
						</tr>
					</tbody>
				</table>
				<table id="pageTable" align="center"
					style="visibility: hidden; margin-top: 30px; font: 12px;"
					class="navigator">
					<tr>
						<td id="pageTd">
						</td>
					</tr>
				</table>
				<!-- systemuser显示div -->
				<div id="sysuserdiv" style="visibility: hidden;">
					<table>
						<tr>
							<td>
								系统用户名:
							</td>
							<td>
								<input id="systemuserid" type="hidden" />
								<input id="systemuserind" type="hidden" />
								<input id="systemuserpassword" type="hidden" />
								<input id="systemuseremail" type="hidden" />
								<input id="systemuserbirthday" type="hidden" />
								<input id="systemuserbirthplace" type="hidden" />
								<input id="systemuseridentitycardno" type="hidden" />
								<input id="systemuseraddress" type="hidden" />
								<input id="systemusername" type="text" size="20" />
							</td>
						</tr>
						<tr>
							<td>
								系统用户显示名:
							</td>
							<td>
								<input id="systemusernickname" type="text" size="20" />
							</td>
						</tr>
						<tr>
							<td>
								系统用户性别
							</td>
							<td>
								<select name="systemusersex" id="systemusersex"
									style="width: 40">
									<option value="1">
										男
									</option>
									<option value="0">
										女
									</option>
								</select>
							</td>
						</tr>
						<tr>
							<td>
								系统用户电话
							</td>
							<td>
								<input type="text" id="systemusertelephone" size="20" />
							</td>
						</tr>
						<tr>
							<td>
								用户所属组
							</td>
							<td>
								<select class="common_select" name="systemusergroupid"
									id="systemusergroupid" style="width: 120">
								</select>
							</td>
						</tr>
						<tr>
							<td colspan="2" align="right">
								<input class="common_button" type="button" value="保存"
									onclick="writeSystemUser()" />
								<input class="common_button" type="button" value="重置"
									onclick="clearSystemUser()" />
							</td>
						</tr>
					</table>
					<div id="loading"
						style="display: none; margin-top: 20px; text-align: center; color: red; font: 13px;">
						Loading...
					</div>
				</div>
			</div>
	</body>
</html>